package com.shq.ex1;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;

public class GaoJiUIActivity extends AppCompatActivity {

    private AutoCompleteTextView autoCompleteTextView = null;
    private Button button = null;
    //进度条
    private ProgressBar horizonPro = null;
    private ProgressBar circlePro = null;
    private TextView textView01;
    private TextView textView02;
    private Button button3;
    private Button btnrestart;
    private int status = 0;
    //拖动条与星级评分
    private SeekBar seekBar = null;
    private TextView tdttext01 = null;
    private TextView tdttext02 = null;
    private TextView xjpfText = null;
    private RatingBar xjpfRatingBar = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gao_ji_ui);

        final String[] COUNTRIES = {"Afghanistan","Albania","Algeria","American Samoa","Andorra",
                "Cayman Islands","Central African Republic","Chad","Chile","China"};
        autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
        button = (Button)findViewById(R.id.button);
        //进度条
        horizonPro = (ProgressBar)findViewById(R.id.horizonPro);
        circlePro = (ProgressBar)findViewById(R.id.circlePro);
        textView01 = (TextView)findViewById(R.id.text01) ;
        textView02 = (TextView)findViewById(R.id.text02) ;
        button3 = (Button)findViewById(R.id.button3);
        btnrestart = (Button)findViewById(R.id.restart);
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(status == 0){
                    button3.setText(R.string.addBtn);
                    horizonPro.setVisibility(View.VISIBLE);
                    circlePro.setVisibility(View.VISIBLE);
                    textView01.setText(R.string.run);
                    textView02.setText(R.string.run);
                    horizonPro.setSecondaryProgress(status + 10);
                }else if (status <= 200){
                    horizonPro.setProgress(status);
                    horizonPro.setSecondaryProgress(status+10);
                    circlePro.setProgress(status);
                }else{
                    horizonPro.setVisibility(View.GONE);
                    circlePro.setVisibility(View.GONE);
                    textView01.setText(R.string.done);
                    textView02.setText(R.string.done);
                    button3.setVisibility(View.GONE);
                    btnrestart.setVisibility(View.VISIBLE);
                }
                status = status + 10;
            }
        });
        btnrestart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                status = 0;
                button3.setText(R.string.startBtn);
                button3.setVisibility(View.VISIBLE);
                btnrestart.setVisibility(View.GONE);
                textView01.setText(R.string.start);
                textView02.setText(R.string.start);
                horizonPro.setProgress(status);
                horizonPro.setSecondaryProgress(status+10);
                circlePro.setProgress(status);
            }
        });

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,COUNTRIES);//创建ArrayAdapter适配器
        autoCompleteTextView.setAdapter(adapter);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("您要搜索的是：", autoCompleteTextView.getText().toString());
            }
        });

        //拖动条与星级评分
        seekBar = (SeekBar)findViewById(R.id.tdtseekBar);
        tdttext01 = (TextView)findViewById(R.id.tdttext01);
        tdttext02 = (TextView)findViewById(R.id.tdttext02);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tdttext01.setText(R.string.tdtdoing);
                tdttext02.setText("当前值为："+ progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                tdttext01.setText(R.string.tdtend);
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                tdttext01.setText(R.string.tdtstart);
            }
        });
        xjpfRatingBar = (RatingBar)findViewById(R.id.xjpfRatinBar);
        xjpfText = (TextView)findViewById(R.id.xjpfText);
        xjpfRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                xjpfText.setText("你得到了"+ rating + "颗星");
            }
        });


    }

}
